package com.hctg.forced2sleep.dialog;

import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.view.View;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;

import com.actor.myandroidframework.dialog.ViewBindingDialog;
import com.blankj.utilcode.util.SizeUtils;
import com.hctg.forced2sleep.R;
import com.hctg.forced2sleep.databinding.DialogTipsIcon2BtnBinding;

/**
 * description: 提示Dialog, 1个icon图片, 2个按钮
 * company    :
 * @author    : ldf
 * date       : 2024/6/14 on 11:57
 */
public class TipsIcon2BtnDialog extends ViewBindingDialog<DialogTipsIcon2BtnBinding> {

    private String title;
    private String content;
    private int icon = R.drawable.icon_alert;
    private String cancelText = "取消";
    private String yesText = "确定";
    private View.OnClickListener yesClickListener;

    public TipsIcon2BtnDialog(@NonNull Context context, String title, String content, View.OnClickListener listener) {
        super(context);
        setWidthPercent(0.888888f, SizeUtils.dp2px(308f));
        this.title = title;
        this.content = content;
        this.yesClickListener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        viewBinding.ivIcon.setImageResource(icon);
        viewBinding.tvTitle.setText(title);
//        viewBinding.tvContent.setText(content);
        viewBinding.tvContent.setText(Html.fromHtml(content));
        viewBinding.ivClose.setOnClickListener(v -> { dismiss(); });
        viewBinding.tvCancel.setText(cancelText);
        viewBinding.tvCancel.setOnClickListener(v -> { dismiss(); });
        viewBinding.tvYes.setText(yesText);
        viewBinding.tvYes.setOnClickListener(v -> {
            dismiss();
            if (yesClickListener != null) yesClickListener.onClick(v);
        });
    }

    public TipsIcon2BtnDialog setIcon(@DrawableRes int icon) {
        this.icon = icon;
        return this;
    }

    public TipsIcon2BtnDialog setCancelText(String cancelText) {
        this.cancelText = cancelText;
        return this;
    }

    public TipsIcon2BtnDialog setYesText(String yesText) {
        this.yesText = yesText;
        return this;
    }

    /**
     * 设置Html形式的内容
     * <big><strong><font color='#F45075'>重启手机</font></strong></big>解决问题！！！
     * @param content
     * @return
     */
//    public Tips2BtnDialog setContentHtml(String content) {
//        this.content = Html.fromHtml(content);
//        return this;
//    }
}
